package com.reform.mapper;

import com.reform.pojo.project.PhaseTime;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.reform.pojo.phase.SimplifyBatch;
import com.reform.pojo.project.PostProject;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 阶段时间表 Mapper 接口
 * </p>
 *
 * @author mortale
 * @since 2021-07-15
 */
@Mapper
public interface PhaseTimeMapper extends BaseMapper<PhaseTime> {

    /**
     * 获取待办事项 教师
     *
     * @param date     当前时间yyyy/mm/dd
     * @param type     阶段类型
     * @return List<SimplifyBatch>
     */
    List<SimplifyBatch> getTeacher(@Param("date") String date, @Param("type") Integer type);
    /**
     * 获取待办事项   专家
     *
     * @param date     当前时间yyyy/mm/dd
     * @param type     阶段类型
     * @return List<SimplifyBatch>
     */
    List<SimplifyBatch> getExpert(@Param("date") String date, @Param("type") Integer type, @Param("gh") String gh);
    /**
     * 获取待办事项 校管理员（1审核）
     *
     * @param date     当前时间yyyy/mm/dd
     * @param type     阶段类型
     * @return List<SimplifyBatch>
     */
    List<SimplifyBatch> getSchoolAdminFirst(@Param("date") String date, @Param("type") Integer type);
    /**
     * 获取待办事项 校管理员（2审核）
     *
     * @param date     当前时间yyyy/mm/dd
     * @param type     阶段类型
     * @return List<SimplifyBatch>
     */
    List<SimplifyBatch> getSchoolAdminSecond(@Param("date") String date, @Param("type") Integer type);
    /**
     * 获取待办事项 院管理员
     *
     * @param date     当前时间yyyy/mm/dd
     * @param type     阶段类型
     * @return List<SimplifyBatch>
     */
    List<SimplifyBatch> getDepartmentAdmin(@Param("date") String date, @Param("type") Integer type);

    /**
     * 获取在规定审核时间内的批次id
     *
     * @param date    当天时间
     * @param batchId 批次id
     * @return batchId
     */
    String getBatchIdByPhaseId(@Param("date") String date, @Param("batchId") String batchId);

    /**
     * 通过batchId修改status
     * @param batchId
     * @param status
     * @return
     */
    @Update("UPDATE `reform`.`phase_time` SET `status` = #{status} WHERE `phase_id` = #{batchId}")
    Integer updateBatchStatusById(@Param("batchId") String batchId, @Param("status") Integer status);

    @Select(
            "SELECT phase_id FROM phase_time WHERE type = ${type}"
    )
    List<String> getPhaseIdByType(@Param("type") int type);

    @Select(
            "SELECT\n" +
            "	project.pro_id AS proId, \n" +
            "	project.pro_name AS proName, \n" +
            "	project.pro_enddate AS endTime, \n" +
            "	batch.batch_name AS batchName, \n" +
            "	phase_time.phase_name AS phaseName\n" +
            "FROM\n" +
            "	project,\n" +
            "	batch,\n" +
            "	batch_phase,\n" +
            "	phase_time\n" +
            "WHERE\n" +
            "	project.pro_approval = ${proApproval} AND\n" +
            "	project.batch_id = batch.batch_id AND\n" +
            "	project.batch_id = batch_phase.batch_id AND\n" +
            "	batch_phase.phase_id = phase_time.phase_id"
    )
    List<PostProject> getDealtProject(@Param("proApproval")int proApproval);

    @Update(
            "UPDATE `reform`.`phase_time` \n" +
            "SET `score_path` = #{scorePath},\n" +
            "`score_path_name` = #{scorePathName}\n" +
            "WHERE\n" +
            "`phase_id` = #{batchId}"
    )
    int updateScore(@Param("batchId") String batchId,@Param("scorePath") String scorePath,@Param("scorePathName") String scorePathName);

    @Select("SELECT phase_id FROM phase_time WHERE phase_id = #{phaseId} and status = #{status}")
    String getPhaseIdByStatus(@Param("phaseId")String phaseId,@Param("status") int status);
}
